사이트 내 전체검색
PHP
Advanced File Search
로빈아빠
https://cmd.kr/php/767 URL이 복사되었습니다.

본문

<?php
class file_search
{
  var $found = array();

  function file_search($files, $dirs = '.', $sub = 1, $case = 0)
  {
    $dirs = (!is_array($dirs)) ? array($dirs) : $dirs;
    foreach ($dirs as $dir)
    {
      $dir .= (!ereg('/$', $dir)) ? '/' : '';
      $directory = @opendir($dir);

      while (($file = @readdir($directory)) !== FALSE)
      {
        if ($file != '.' && $file != '..')
        {
          if ($sub && is_dir($dir . $file))
          {
            $this->file_search($files, $dir . $file, $sub, $case);
          }
          else
          {
            $files = (!is_array($files)) ? array($files) : $files;
            foreach ($files as $target)
            {
              $tar_ext = substr(strrchr($target, '.'), 1);
              $tar_name = substr($target, 0, strrpos($target, '.'));
              $fil_ext = substr(strrchr($file, '.'), 1);
              $fil_name = substr($file, 0, strrpos($file, '.'));

              $ereg = ($case) ? 'ereg' : 'eregi';
              if ($ereg($tar_name, $fil_name) && eregi($tar_ext, $fil_ext))
              {
                $this->found[] = $dir . $file;
              }
            }
          }
        }
      }
    }
  }
}

$find = array('test.[^php]', 'contact.php|html');
$search = new file_search($find);

echo '<pre>';
print_r($search->found);
echo '</pre>';
?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (4/18P)

Search

Copyright © Cmd 명령어 3.138.102.114